﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace The_LarX
{
    public class ContentLoaded
    {
        public object Content;
        public int ObjectsUsing;
        private LarCustomContentManager content;
        private string fileName;
        public string FileName
        {
            get { return fileName; }
        }
        public LarCustomContentManager ContentManager
        {
            get { return content; }
        }        

        public ContentLoaded(object obj, string fileName, LarCustomContentManager content)
        {
            this.fileName = fileName;
            this.content = content;
            Content = obj;
            ObjectsUsing = 1;
        }

        public void LoadedAgain()
        {
            ObjectsUsing++;
        }
        public void Dispose()
        {
            ObjectsUsing--;
            if (ObjectsUsing == 0)
            {
                if (Content is IDisposable)
                    (Content as IDisposable).Dispose();

                content.Content.Remove(this.fileName);
            }
        }
    }
}
